package cn.eud.hunau.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.eud.hunau.mapper.MovieMapper;
import cn.eud.hunau.pojo.Movie;
import cn.eud.hunau.service.MovieService;

@Service
public class MovieServiceImpl implements MovieService {
    @Autowired
    private MovieMapper movieMapper;

    // 查询所有电影
    @Override
    public List<Movie> selectAll() {
        return movieMapper.selectAll();
    }

    // 根据电影id查询电影
    @Override
    public Movie selectById(Integer id) {
        return movieMapper.selectById(id);
    }

    //收藏电影
    @Override
    public boolean likeMovie(Long userId, Long movieId) {
        return movieMapper.insertUserLikeMovie(userId, movieId) > 0;
    }

    //取消收藏电影
    @Override
    public boolean unlikeMovie(Long userId, Long movieId) {
        return movieMapper.deleteUserLikeMovie(userId, movieId) > 0;
    }

    //查询收藏电影
    @Override
    public List<Movie> getLikedMovies(Long userId) {
        return movieMapper.selectLikedMoviesByUserId(userId);
    }

    //判断电影是否收藏
    @Override
    public boolean isMovieLiked(Long userId, Long movieId) {
        Integer count = movieMapper.isMovieLikedByUser(userId, movieId);
        return count != null && count > 0;
    }

    @Override
    public boolean rateMovie(Long userId, Long movieId, Integer score) {
        return movieMapper.insertUserRateMovie(userId, movieId, score) > 0;
    }

    @Override
    public Integer getUserScore(Long userId, Long movieId) {
        return movieMapper.selectUserScore(userId, movieId);
    }

    @Override
    public java.util.List<cn.eud.hunau.pojo.UserRateMovie> getMovieScores(Long movieId) {
        return movieMapper.selectMovieScores(movieId);
    }

    @Override
    public boolean commentMovie(Long userId, Long movieId, String comment) {
        return movieMapper.insertUserCommentMovie(userId, movieId, comment) > 0;
    }

    @Override
    public java.util.List<cn.eud.hunau.pojo.UserCommentMovie> getMovieComments(Long movieId) {
        return movieMapper.selectMovieComments(movieId);
    }

    @Override
    public java.util.List<cn.eud.hunau.pojo.UserCommentMovie> getUserComments(Long userId, Long movieId) {
        return movieMapper.selectUserComments(userId, movieId);
    }

    @Override
    public boolean updateComment(Long commentId, Long userId, String comment) {
        return movieMapper.updateUserCommentMovie(commentId, userId, comment) > 0;
    }

    @Override
    public boolean deleteComment(Long commentId, Long userId) {
        return movieMapper.deleteUserCommentMovie(commentId, userId) > 0;
    }

    @Override
    public java.util.List<cn.eud.hunau.pojo.Movie> getHotMovies(int limit) {
        return movieMapper.selectHotMovies(limit);
    }

    @Override
    public java.util.List<Movie> getMoviesByConditions(Long typeId, Long regionId, Long languageId) {
        return movieMapper.selectMoviesByConditions(typeId, regionId, languageId);
    }

    @Override
    public java.util.List<cn.eud.hunau.pojo.Type> getAllTypes() {
        return movieMapper.selectAllTypes();
    }

    @Override
    public java.util.List<cn.eud.hunau.pojo.Region> getAllRegions() {
        return movieMapper.selectAllRegions();
    }

    @Override
    public java.util.List<cn.eud.hunau.pojo.Language> getAllLanguages() {
        return movieMapper.selectAllLanguages();
    }
}